package cn.hesion.prototype;

import java.util.ArrayList;
import java.util.List;

public class PrototypeTest {
    public static void main(String[] args) {
        //创建一个具体的需要克隆的对象
        ConcretePrototypeA concretePrototypeA = new ConcretePrototypeA();
        concretePrototypeA.setAge(18);
        concretePrototypeA.setName("prototype");
        List<String> hobbies = new ArrayList<>();
        concretePrototypeA.setHobbies(hobbies);
        System.out.println(concretePrototypeA);


        //创建Client对象
        Client client = new Client(concretePrototypeA);
        ConcretePrototypeA concretePrototypeClone = (ConcretePrototypeA) client.startClone(concretePrototypeA);
        System.out.println(concretePrototypeClone);
        System.out.println("克隆对象引用地址:"+concretePrototypeClone.getHobbies());
        System.out.println("原始对象中引用类型地址值:"+concretePrototypeA.getHobbies());
        System.out.println("地址比较:"+(concretePrototypeA.getHobbies()==concretePrototypeClone.getHobbies()));

    }
}
